package com.health.mapper;

import com.health.entity.TRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.health.entity.pojo.vo.AdminVO;
import com.health.entity.pojo.vo.TRoleVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sanchuan
 * @since 2023-04-20
 */
public interface TRoleMapper extends BaseMapper<TRole> {

    // 获得角色列表
    @Select("SELECT r.id,r.name,r.description,r.create_time,r.is_shelves FROM `t_role` r,`t_admin_role` ar WHERE is_deleted  = 0 GROUP BY r.name")
    List<TRoleVO> listRoles();

    // 获得 当前角色下的人员列表
    @Select("SELECT * FROM admin WHERE role_id = #{rid}")
    List<AdminVO> listAdmin(Integer rid);

    // 获得 当前角色下的人员总数
    @Select("SELECT count(id) FROM admin WHERE role_id = #{rid}")
    Integer adminCount(Integer rid);

    // 更新启用状态
    @Update("UPDATE `t_role` SET is_shelves = #{isShelves} WHERE id = #{id} ")
    Boolean updateShelves(@Param("isShelves") Boolean isShelves, @Param("id") Integer id);

    @Select("SELECT r.id,r.name,r.description,r.create_time,r.is_shelves " +
            "FROM `t_role` r,`t_admin_role` ar WHERE is_deleted  = 0 AND department_id = #{departmentId} GROUP BY r.name")
    List<TRoleVO> listRolesByDID(Integer departmentId);
}
